package com;

/**
 * Created by wangyg on 2016/11/17.
 */
public class Entity {
	private String name;
	private String sex;
	private Integer age;
	private Double height;
	private Double weigth;
	private String hah;

	//私有构造方法
	private Entity(Builder b){
		this.age=b.age;
		this.name=b.name;
		this.sex=b.sex;
		this.height=b.height;
		this.weigth=b.weight;
	}

	@Override
	public String toString() {
		return "Entity{" +
				"name='" + name + '\'' +
				", sex='" + sex + '\'' +
				", age=" + age +"岁"+
				", hight=" + height +"cm"+
				", weigth=" + weigth +"kg"+
				'}';
	}

	//为了避免构造方法太复杂,因为可能有多种组合构建对象，也可以避免一直的set对象，这里可以用一种builder(InnerClass)的方式创建
	public static class  Builder{
		private String name;
		private String sex;
		private Integer age;
		private Double height;
		private Double weight;

		public Builder setName(String name){
			this.name=name;
			return this;
		}
		public Builder setSex(String sex){
			this.sex=sex;
			return this;
		}
		public Builder setAge(Integer age){
			this.age=age;
			return this;
		}
		public Builder setHeight(Double height){
			this.height=height;
			return this;
		}
		public Builder setWeight(Double weight){
			this.weight=weight;
			return this;
		}

		public Entity builder(){
			return new Entity(this);
		}
	}

	public static void main(String[] args) {
		 Entity entity = new Builder().setName("WangYueguo").setAge(25).setSex("男").setHeight(178.5).setWeight(64.5)
				.builder();
		System.out.println(entity.toString());
	}
}
